# Definition for singly-linked list.
class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None


class Solution:
    def swapPairs(self, head: ListNode) -> ListNode:
        if not head:
            return None
        elif not head.next:
            return head
        head, head.next, head.next.next = head.next, head, head.next.next
        now_note = head.next
        try:
            while True:
                now_note.next, now_note.next.next, now_note.next.next.next = \
                    now_note.next.next, now_note.next, now_note.next.next.next
                now_note = now_note.next.next
        except:
            return head